fix(Input, Textarea): keep 0 with the nullable and optional modifiers - #6871
fix(Input, Textarea): keep 0 with the nullable and optional modifiers#6871giaBaoJS wants to merge 1 commit into
0 with the nullable and optional modifiers#6871Conversation
`||=` fires on every falsy value, so with the `number` modifier (or `type="number"` on Input) a typed `0` was turned into `null` or `undefined` before it reached the model. Map only genuinely empty values instead. `''` still becomes `null` or `undefined`, which is why `??=` is not the right operator here.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughInput and Textarea now detect empty values explicitly before applying Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This localized fix preserves typed zero values while retaining existing empty-value behavior in Input and Textarea, with regression coverage; no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
src/runtime/components/Input.vueParsing error: Unexpected token ) src/runtime/components/Textarea.vueParsing error: Unexpected token ) test/components/Input.spec.tsParsing error: Unexpected token {
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
🔗 Linked issue
Resolves #5950
❓ Type of change
📚 Description
InputandTextareamapped empty values with||=:||=fires on every falsy value, so combined with thenumbermodifier (ortype="number"onInput) a typed0went throughlooseToNumber('0')→0and then0 ||= null→null..optionalhad the same problem and producedundefined. Both are the case @sandros94 described in the issue.??=is not the fix:InputandTextareamust still map'', which??=would leave untouched. The mapping is now driven by an explicit emptiness test, so'',nullandundefinedbehave exactly as before and only falsy numbers change:Select,SelectMenu,InputMenuandListboxalready use??=, which is right for them — their value is an option, not a typed string — so they are untouched.Nine table-driven rows added across
Input.spec.tsandTextarea.spec.ts, covering both the0cases and the''cases that must not regress. Reverting only the component change turns the five0rows red in both thenuxtandvueprojects, while the''rows stay green.📝 Checklist